<template>

	<flow-node-format :row="row" :node-user="nodeUser" :disableSelect="disableSelect" ref="flowNodeFormatRef">
	</flow-node-format>

</template>

<script setup lang="ts">
// 工作流审批轨迹-节点数据页面
import { defineExpose, onMounted, ref, watch } from "vue";
import { deepCopy } from "../../utils/objutil";
import { formatStartNodeShow } from "../../api/base";
// 工作流审批轨迹-节点格式
import FlowNodeFormat from "./FlowNodeFormat.vue";

const row = ref([]);
const selectUserNodeIdList = ref([]);
const disableSelect = ref(true);
const paramMapData = ref({})
const nodeUser = ref({})

/**
 * 查询数据
 * @param p 参数的对象
 * @param fid 流程模版id
 * @param pid 流程实例id
 * @param tid 任务id
 * @param f 表单
 */
const queryData = (p, fid, pid, tid, f) => {
	var data = {
		flowId: fid,
		processInstanceId: pid,
		paramMap: p,
		taskId: tid,
		from: f
	}
	paramMapData.value = data;
	refresh();
}

/**
 * 处理已经存在的需要选择人员处理节点 
 * @param list 
 */
function handleExistNodeUser(list) {
	// nodeUser.value={};
	let filter = list
		.filter(res => res.status == 0)
		.filter(res => res.selectUser == true)
		.filter(res => res.type == 1);

	for (var item of filter) {
		let userVoList = deepCopy(item.userVoList);
		if (userVoList && userVoList.length > 0) {
			for (var u of userVoList) {
				u.type = 'user'
			}
			nodeUser.value[item.id] = userVoList;
		}
		item.userVoList = [];
	}
}

/**
 * 验证
 * @param op 
 */
const validate = (op) => {
	if (op !== 'pass') {
		//只有通过 才校验
		return true;
	}
	return true;
}

/**
 * 选择节点用户
 */
const formatSelectNodeUser = () => {
	var obj = {}
	return obj;
}

/**
 * 刷新
 */
const refresh = () => {
	formatStartNodeShow(paramMapData.value).then(res => {
		row.value = res.data.processNodeShowDtoList;
		disableSelect.value = res.data.disableSelectUser
		selectUserNodeIdList.value = res.data.selectUserNodeIdList;
		handleExistNodeUser(row.value)
	})
}

/**
 * 定义暴露
 */
defineExpose({ validate, refresh, formatSelectNodeUser, queryData });
onMounted(() => {})
</script>

<style scoped lang="less"></style>
